/*
 * @Author: wangqizhang
 * @Date: 2024-05-04 14:11:07
 * @LastEditors: wangqizhang
 * @LastEditTime: 2024-05-07 08:44:25
 * @FilePath: /suixinji-server/service/note.service.js
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
const { runSqlTask, initSqlTask } = require('../service');
const { Note } = require('../model/note.model');
class NoteService {
  async addNote(body) {
    try {
      const res = await runSqlTask(initSqlTask(Note, 'create', body));
      return res;
    } catch (error) {
      console.log(error);
      return error;
    }
  }
  async findNoteList(id) {
    try {
      const res = await runSqlTask(
        initSqlTask(Note, 'findAll', {
          user_id: id,
        })
      );
      return res;
    } catch (error) {
      return error;
    }
  }
  findNoteById(id) {
    try {
      const res = runSqlTask(initSqlTask(Note, 'findOne', { id }));
      return res;
    } catch (error) {
      return error;
    }
  }
  findNoteByGroupId(id) {
    try {
      const res = runSqlTask(initSqlTask(Note, 'findAll', { group_id: id }));
      return res;
    } catch (error) {
      return error;
    }
  }
  async updateNoteData(body) {
    try {
      const res = await runSqlTask(initSqlTask(Note, 'update', body));
      return res;
    } catch (error) {
      return error;
    }
  }
  async findDefaultNote(userId) {
    try {
      const res = await runSqlTask(
        initSqlTask(Note, 'findAll', {
          user_id: userId,
          group_id: 1111,
        })
      );
      return res;
    } catch (error) {
      return error;
    }
  }
}
module.exports = new NoteService();
